using HZY.Framework.Repository.EntityFramework.Interceptor;
using HZY.Framework.Repository.EntityFramework.Monitor;
using HZY.Framework.Repository.EntityFramework.Monitor.Models;
using HZY.Framework.Repository.EntityFramework.Test.DbContexts;
using HZY.Framework.Repository.EntityFramework.Test.Models;
using HZY.Framework.Repository.EntityFramework.Test.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using FreeSql.Internal.Model;
using HZY.Framework.Repository.EntityFramework.Models;
using IdGen;
using MySqlConnector;

namespace HZY.Framework.Repository.EntityFramework.Test.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class TestController : ControllerBase
    {
        private readonly ILogger<TestController> _logger;
        private readonly AppDbContext _appDbContext;
        private readonly AppDbContext1 _appDbContext1;
        private readonly IServiceProvider _serviceProvider;
        private readonly IRepository<SysFunction> _sysFunctionRepository;
        private readonly IRepository<AppTest> _appTestRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="appDbContext"></param>
        /// <param name="serviceProvider"></param>
        public TestController(ILogger<TestController> logger,
            AppDbContext appDbContext,
            IServiceProvider serviceProvider,
            IRepository<SysFunction> sysFunctionRepository,
            IRepository<AppTest> appTestRepository)
        {
            _logger = logger;
            _appDbContext = appDbContext;
            _serviceProvider = serviceProvider;
            _sysFunctionRepository = sysFunctionRepository;
            _appTestRepository = appTestRepository;
            //_appDbContext1 = appDbContext1;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet("Update")]
        public async Task<string> Update()
        {
            var repository = new AppRepository<SysFunction>(_appDbContext, _serviceProvider);
            var sysFunction = await repository.Select.FirstOrDefaultAsync();
            sysFunction.CreationTime = DateTime.Now;
            repository.Update(sysFunction);
            var a = repository.UnitOfWork.DbSet<SysFunction>();
            if (sysFunction == null) return "OK";

            var resultCount = repository.UpdateBulk(
                w => w
                    .SetProperty(s => s.Name, s => sysFunction.Name)
                    .SetProperty(s => s.Number, s => 1000)
                ,
                w => w.Id == sysFunction.Id && w.Name == sysFunction.Name
            );

            return "Ok" + resultCount;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet("Delete")]
        public async Task<string> Delete()
        {
            var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
                .UseSqlServer(
                    @"Server=.;Database=hzy_admin_sqlserver_20220730;User ID=sa;Password=123456;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;");
            contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
            contextOptions.AddInterceptors(new ShardingDbCommandInterceptor());
            using var context = new AppDbContext(contextOptions.Options);
            var repository = new AppRepository<SysFunction>(context, _serviceProvider);
            var sysFunction = await repository.Select.AsTable("sys_function").FirstOrDefaultAsync();

            if (sysFunction == null) return "OK";

            var resultCount =
                await repository.DeleteBulkAsync(w => w.Id == sysFunction.Id && w.Name == sysFunction.Name);

            sysFunction = repository.Insert(sysFunction);

            return "Ok" + resultCount;
        }

        /// <summary>
        /// sql 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("QueryBySql")]
        public async Task<string> QueryBySql()
        {
            var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
                .UseSqlServer(
                    @"Server=.;Database=hzy_admin_sqlserver_20220920;User ID=sa;Password=123456;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;");

            contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));

            using var context = new AppDbContext(contextOptions.Options);

            var list = await context.Set<SysFunction>().FromSqlRaw("select * from sys_function").ToListAsync();

            var repository = new AppRepository<SysFunction>(context, _serviceProvider);

            var dt = repository.QueryDataTableBySql("select * from sys_function");
            var dt1 = await repository.QueryDataTableBySqlAsync("select * from sys_function");

            var listDic = repository.QueryDicBySql("select * from sys_function");
            var listDic1 = await repository.QueryDicBySqlAsync("select * from sys_function");

            var list1 = repository.QueryBySql("select * from sys_function");
            var list2 = await repository.QueryBySqlAsync("select * from sys_function");

            var id = repository.QuerySingleBySql<Guid>("select id from sys_function");
            var id1 = await repository.QuerySingleBySqlAsync<Guid>("select id from sys_function");

            var count = await repository.QuerySingleBySqlAsync<int>("select count(1) from sys_function");

            var model = await repository.SelectNoTracking.FirstOrDefaultAsync();
            model.ByName = model.ByName + "1";

            // 验证实体是否被跟踪
            bool isTracked = context.ChangeTracker.Entries().Any(e => e.Entity == model);

            repository.DetachWhenExist(w => w.Id == model.Id);
            repository.Update(model);

            return "Ok" + list.Count();
        }
        //
        // /// <summary>
        // /// sqlserver 批量拷贝
        // /// </summary>
        // /// <returns></returns>
        // [HttpGet("SqlServerBulkCopyAsync")]
        // public async Task<string> SqlServerBulkCopyAsync()
        // {
        //     var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
        //         .UseSqlServer(
        //             @"Server=.;Database=HzyAdminSpa20220410;User ID=sa;Password=123456;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;");
        //
        //     contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
        //
        //     using var context = new AppDbContext(contextOptions.Options);
        //
        //     var list = await context.Set<SysFunction>().FromSqlRaw("select * from SysFunction").ToListAsync();
        //
        //     var repository = new AppRepository<SysFunction>(context, _serviceProvider);
        //
        //     //拷贝
        //     foreach (var item in list)
        //     {
        //         item.Id = Guid.NewGuid();
        //         item.Name += "批量拷贝";
        //     }
        //
        //     await repository.SqlServerBulkCopyAsync(list);
        //
        //     return "Ok" + list.Count();
        // }
        //
        // /// <summary>
        // /// mysql 批量拷贝
        // /// </summary>
        // /// <returns></returns>
        // [HttpGet("MySqlBulkCopy")]
        // public string MySqlBulkCopy()
        // {
        //     //mysql
        //     var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
        //         .UseMySql(
        //             @"Server=localhost; port=3306; Database=HzyAdminSpa; uid=root; pwd=123456; Convert Zero Datetime=False;AllowLoadLocalInfile=true",
        //             MySqlServerVersion.LatestSupportedServerVersion, w => w.MinBatchSize(1).MaxBatchSize(1000));
        //
        //     contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
        //
        //     using var context = new AppDbContext(contextOptions.Options);
        //
        //     var repository = new AppRepository<SysFunction>(context, _serviceProvider);
        //
        //     var list = repository.QueryBySql("select * from SysFunction");
        //
        //     repository.MySqlBulkCopy(list);
        //
        //     return "Ok";
        // }

        /// <summary>
        /// MyDbCommandInterceptor
        /// dbcommand 拦截
        /// </summary>
        /// <returns></returns>
        [HttpGet("MyDbCommandInterceptor")]
        public async Task<string> MyDbCommandInterceptor()
        {
            //mysql
            var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
                    .UseMySql(
                        @"Server=localhost; port=3306; Database=HzyAdminSpa; uid=root; pwd=123456; Convert Zero Datetime=False;AllowLoadLocalInfile=true",
                        MySqlServerVersion.LatestSupportedServerVersion, w => w.MinBatchSize(1).MaxBatchSize(1000))
                ;

            contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));

            using var context = new AppDbContext(contextOptions.Options);

            var repository = new AppRepository<SysFunction>(context, _serviceProvider);

            var tableName = $"SysFunction_{DateTime.Now.ToString("yyyyMMdd")}";

            var list = await repository.Select.Where(w => w.ByName == "Insert").AsTable(tableName).ToListAsync();
            var list1 = await repository.Select.Where(w => w.ByName == "Update").AsTable(tableName).ToListAsync();

            var Count = repository.Select.AsTable(tableName).Count();

            return "Ok";
        }

        /// <summary>
        /// EFCoreMonitorContext efcore 程序监控
        /// </summary>
        /// <returns></returns>
        [HttpGet("EFCoreMonitorContext")]
        public EntityFrameworkRepositoriesMonitorContext? EFCoreMonitorContext()
        {
            return RepositoryEntityFrameworkMonitorCache.Context;
        }

        /// <summary>
        /// SqlMonitorContext sql 监控
        /// </summary>
        /// <returns></returns>
        [HttpGet("SqlMonitorContext")]
        public List<EntityFrameworkRepositoriesMonitorSqlContext>? SqlMonitorContext()
        {
            return RepositoryEntityFrameworkMonitorCache.SlowSqlContext;
        }

        /// <summary>
        /// 获取所有表信息
        /// 
        /// 
        /// https://www.cnblogs.com/osmeteor/p/3429229.html
        /// 
        /// 
        /// </summary>
        /// <returns></returns>
        // [HttpGet("GetTabls_SqlServer")]
        // public bool GetTabls_SqlServer()
        // {
        //     var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
        //         .UseSqlServer(
        //             @"Server=.;Database=hzy_admin_sqlserver_20221213;User ID=sa;Password=123456;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;");
        //
        //     contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
        //
        //     using var context = new AppDbContext(contextOptions.Options);
        //
        //     var repository = new AppRepository<SysFunction>(context, _serviceProvider);
        //
        //     var tables = repository.GetTables();
        //     var columns = repository.GetColumns();
        //     var dataTypes = repository.GetDataTypes();
        //
        //     return true;
        // }


        /// <summary>
        /// 获取所有表信息
        /// 
        /// 
        /// https://www.cnblogs.com/osmeteor/p/3429229.html
        /// 
        /// 
        /// </summary>
        /// <returns></returns>
        // [HttpGet("GetTabls_MySql")]
        // public bool GetTabls_MySql()
        // {
        //     var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
        //         .UseMySql(
        //             @"Server=localhost; port=3306; Database=hzy_admin_mysql_20221213; uid=root; pwd=123456; Convert Zero Datetime=False",
        //             MySqlServerVersion.LatestSupportedServerVersion);
        //
        //     contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
        //
        //     using var context = new AppDbContext(contextOptions.Options);
        //
        //     var repository = new AppRepository<SysFunction>(context, _serviceProvider);
        //
        //     var tables = repository.GetTables();
        //     var columns = repository.GetColumns();
        //     var dataTypes = repository.GetDataTypes();
        //
        //     return true;
        // }

        /// <summary>
        /// 获取所有表信息
        /// 
        /// 
        /// https://www.cnblogs.com/osmeteor/p/3429229.html
        /// 
        /// 
        /// </summary>
        /// <returns></returns>
        // [HttpGet("GetTabls_NPgsql")]
        // public bool GetTabls_NPgsql()
        // {
        //     var contextOptions = new DbContextOptionsBuilder<AppDbContext>()
        //         .UseNpgsql(
        //             @"User ID=postgres;Password=123456;Host=localhost;Port=5432;Database=hzy_admin_pgsql_20221213;Pooling=true;TimeZone=Asia/Shanghai");
        //
        //     contextOptions.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
        //
        //     using var context = new AppDbContext(contextOptions.Options);
        //
        //     var repository = new AppRepository<SysFunction>(context, _serviceProvider);
        //
        //     var tables = repository.GetTables();
        //     var columns = repository.GetColumns();
        //     var dataTypes = repository.GetDataTypes();
        //
        //     return true;
        // }

        /// <summary>
        /// 
        /// </summary>
        [HttpGet("ReadDatabaseMetadata")]
        public void ReadDatabaseMetadata()
        {
            _appDbContext.Database.Migrate();

            var migrations = _appDbContext.Database.GetMigrations();

            var migrations1 = _appDbContext.Database.GetAppliedMigrations();

            var migrator = _appDbContext.GetService<IMigrator>();

            foreach (var migration in migrations)
            {
                //var migrationEntry = migrator.GetMigrationEntry(migration);
                //var model = migrationEntry?.GetModel();

                // 在这里处理模型信息，例如查看实体类型、属性等
            }
        }

        [HttpGet("Test1")]
        public void Test1()
        {
            var q = new SysFunction();
            var modelType = q.GetType();
            var number = modelType.GetProperty("Number");

            if (EntityFrameworkUtil.IsNullableType(number.PropertyType))
            {
                //var lambdaQuery1 = ExpressionTreeExtensions.Equal(modelType, "Number"!, 0, number.PropertyType);
                //var lambdaQuery2 = ExpressionTreeExtensions.Equal(modelType, "Number"!, null, number.PropertyType);

                //var query = lambdaQuery1.Or(lambdaQuery2, modelType);

                //var arr = new List<int?>();
                //arr.Add(1);
                //arr.Add(0);
                //arr.Add(null);

                //var data = _sysFunctionRepository.UnitOfWork.FreeSqlOrm?.Select<SysFunction>().Where((Expression<Func<SysFunction, bool>>)query).ToList();
            }


            var list = _sysFunctionRepository.UnitOfWork.FreeSqlOrm?.Select<SysFunction>().ToList();

            foreach (var item in list)
            {
                item.Name = item.Name + "1";
            }

            var result = _sysFunctionRepository.UnitOfWork.FreeSqlOrm?.Update<SysFunction>().SetSource(list)
                .ExecuteAffrows();
        }

        /// <summary>
        /// 
        /// </summary>
        [HttpGet("Test2")]
        public void Test2()
        {
            var q = new SysFunction();

            var list = _sysFunctionRepository.SelectNoTracking.ToList();
        }

        /// <summary>
        /// 
        /// </summary>
        [HttpGet("Test3")]
        public void Test3()
        {
            var q = new SysFunction();

            var list = _sysFunctionRepository.SelectNoTracking.ToList();
        }

        /// <summary>
        /// 
        /// </summary>
        [HttpGet("Test4")]
        public void Test4()
        {
            var q = new SysFunction();

            var list = _sysFunctionRepository.SelectNoTracking.ToList();

            var ty = typeof(string);

            var lambdaLeft = EntityFrameworkUtil.Equal(q.GetType(), "Name", "hzy", typeof(string));
            var lambdaRight = EntityFrameworkUtil.Equal(q.GetType(), "Name", null, typeof(string));
            //var lambda = EntityFrameworkUtil.Or(lambdaLeft, lambdaRight);
            // var body = EntityFrameworkUtil.Or(lambdaLeft, lambdaRight, q.GetType());
        }

        /// <summary>
        /// 
        /// </summary>
        [HttpGet("Test5")]
        public void Test5()
        {
            var list = _sysFunctionRepository.SelectNoTracking.ToList();

            var q = list.FirstOrDefault();
            q.Remark = DateTime.Now.ToString();

            _sysFunctionRepository.InsertOrUpdateAsync(q).Wait();
        }

        [HttpGet("Test6")]
        public void Test6()
        {
            _sysFunctionRepository.Insert(new SysFunction
            {
                Id = Guid.NewGuid(),
                Name = "Test1",
                ByName = "Test1",
                CreationTime = DateTime.Now,
                LastModificationTime = DateTime.Now
            });
        }

        [HttpGet("Test7")]
        public void Test7()
        {
            // 多个字典
            var list = _sysFunctionRepository.SelectNoTracking.ToList();
            var newList = _sysFunctionRepository.GetListByDict(list);
            // 单个字典
            var input = _sysFunctionRepository.SelectNoTracking.FirstOrDefault();
            var inputData = _sysFunctionRepository.GetDictByDict(input ?? new SysFunction());
            // 多个实体
            var list1 = _sysFunctionRepository.SelectNoTracking.ToList();
            var newList1 = _sysFunctionRepository.GetListByDict(list1);
            // 单个实体
            var input1 = _sysFunctionRepository.SelectNoTracking.FirstOrDefault();
            var inputData1 = _sysFunctionRepository.GetByDict(input1 ?? new SysFunction());
            // 多数据转excel
            // var excelStream = _sysFunctionRepository.ToMappingExcel(list2);
            var freeSqlList = _sysFunctionRepository.UnitOfWork.FreeSqlOrm?.Select<SysFunction>().ToList();

            _sysFunctionRepository.UnitOfWork.FreeSqlOrm.CodeFirst.SyncStructure(new TableInfo(), "");
        }
        
        [HttpGet("Test8")]
        public void Test8()
        {
            var freeSqlList = _sysFunctionRepository.UnitOfWork.FreeSqlOrm?.Select<SysFunction>().ToList();
        }

        // [HttpGet("Test8")]
        // public FileResult Test8()
        // {
        //     // 多数据转excel
        //     var list2 = _sysFunctionRepository.SelectNoTracking.ToList();
        //     var excel = _dataDictionaryMappingIntercept.ToMappingExcel(list2);
        //
        //     return this.File(excel, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        //         "我是excel.xlsx");
        // }

        /// <summary>
        /// 主从测试
        /// </summary>
        [HttpGet("Test9")]
        public void Test9()
        {
            var list = _sysFunctionRepository.SelectNoTracking.ToList();

            var q = list.FirstOrDefault();
            if (q is null)
            {
                var next = new Random().Next(1, 1000);
                q = new SysFunction();
                q.Name = "Test1-" + next;
                q.ByName = "Test1-" + next;
            }

            q.Remark = DateTime.Now.ToString(CultureInfo.InvariantCulture);

            _sysFunctionRepository.InsertOrUpdateAsync(q).Wait();
        }

        /// <summary>
        /// 批量插入or更新测试
        /// </summary>
        [HttpGet("Test10")]
        public int Test10()
        {
            var list = _sysFunctionRepository.SelectNoTracking.ToList();
            var saveList = new List<SysFunction>();
            var en = list.FirstOrDefault();
            if (en is not null)
            {
                en.Remark = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                saveList.Add(en);
            }

            //

            var next = new Random().Next(1, 1000) + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
            var q = new SysFunction();
            q.Name = "Test1-" + next;
            q.ByName = "Test1-" + next;
            saveList.Add(q);

            return _sysFunctionRepository.InsertOrUpdateRangeAsync(saveList).Result;
        }

        /// <summary>
        /// 动态条件
        /// </summary>
        [HttpGet("Test11")]
        public int Test11()
        {
            // var _interpreter = new Interpreter(InterpreterOptions.Default | InterpreterOptions.LambdaExpressions);
            //
            // var asExpression1 = _interpreter
            //     .Reference(typeof(SysFunction))
            //     .ParseAsExpression<Func<dynamic, bool>>("""
            //                                             (w as SysFunction).Name=="保存"
            //                                             """, "w");
            //
            // var list1 = _sysFunctionRepository.SelectNoTracking.Where(asExpression1).ToList();
            //
            // // 动态参数
            // var parameter = Expression.Parameter(typeof(SysFunction), "w");
            // var parameterExpression = Expression.Convert(parameter, typeof(SysFunction));
            //
            // var asExpression = _interpreter
            //     // .Reference(typeof(SysFunction))
            //     .SetExpression("w", parameterExpression)
            //     // .SetVariable("s", parameterExpression)
            //     .ParseAsExpression<Func<dynamic, bool>>("""
            //                                             w.Name=="保存"
            //                                             """, "w");
            // var list = _sysFunctionRepository.Where(_sysFunctionRepository.SelectNoTracking, asExpression).ToList();
            //
            // return list.Count;
            return 0;
        }

        /// <summary>
        /// 动态条件2
        /// </summary>
        [HttpGet("Test12")]
        public int Test12()
        {
            // 根据 System.Linq.Dynamic.Core 生成动态条件
            var lambdaExpression = DynamicExpressionParser.ParseLambda(typeof(SysFunction), typeof(bool),
                $" w=> w.Name == \"保存\" ");

            var list = _sysFunctionRepository.Select.Where(lambdaExpression).ToList();

            return list.Count;
        }

        /// <summary>
        /// 动态条件2
        /// </summary>
        [HttpGet("Test13")]
        public int Test13()
        {
            // 被全局拦截软删除
            var list = _sysFunctionRepository.Select.ToList();

            // 没有被全局拦截
            var list2 = _sysFunctionRepository.Select.IgnoreQueryFilters().ToList();

            _sysFunctionRepository.Delete(list.FirstOrDefault());

            return list.Count;
        }

        /// <summary>
        /// 动态条件2
        /// </summary>
        [HttpGet("Test14_insert")]
        public int Test14()
        {
            // 被全局拦截软删除
            var list = _appTestRepository.Select.FirstOrDefault();

            var appTest = new AppTest();
            appTest.Name = "Test1";
            _appTestRepository.Insert(appTest);

            return 1;
        }

        /// <summary>
        /// 动态条件2
        /// </summary>
        [HttpGet("Test14_update")]
        public int Test15_update()
        {
            // 被全局拦截软删除
            var appTest = _appTestRepository.Select.FirstOrDefault();
            appTest.Name = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            _appTestRepository.InsertOrUpdate(appTest);
            return 1;
        }

        /// <summary>
        /// 动态条件2
        /// </summary>
        [HttpGet("Test14_delete")]
        public int Test15_delete()
        {
            // 被全局拦截软删除
            var appTest = _appTestRepository.Select.FirstOrDefault();
            // appTest.Name = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            _appTestRepository.Delete(appTest);
            return 1;
        }

        /// <summary>
        /// 字段加解密
        /// </summary>
        [HttpGet("Test16_TableFieldEncrypt")]
        public SysFunction? Test16_TableFieldEncrypt()
        {
            // 被全局拦截软删除
            var appTest = _sysFunctionRepository.Select.FirstOrDefault();
            // appTest.Name = DateTime.Now.ToString(CultureInfo.InvariantCulture);

            return appTest;
        }

        /// <summary>
        /// 字段加解密
        /// </summary>
        [HttpGet("Test17_FreeSql")]
        public bool? Test17_FreeSql()
        {
            // 被全局拦截软删除
            var appTest = _appTestRepository.Select.FirstOrDefault();
            var aa = new AppTest();
            aa.Name = "1111";
            // appTest.Name = DateTime.Now.ToString(CultureInfo.InvariantCulture);

            var insertOrUpdateRange = _appTestRepository.InsertOrUpdateRange([appTest, aa]);

            return _appTestRepository.InsertOrUpdateByFreeSql([appTest, aa]) > 0;
        }

        /// <summary>
        /// 字段加解密
        /// </summary>
        [HttpGet("Test18")]
        public bool? Test18()
        {
            // 被全局拦截软删除
            var appTest = _appTestRepository.Select
                .FirstOrDefault(w => w.Id == "1315333910925672448");
            appTest.UpdateTime = DateTime.Now.AddDays(5);

            return _appTestRepository.UpdateBatchByFreeSql([appTest]) > 0;
        }

        /// <summary>
        /// 验证如果 集合为空 那么条件是什么样子
        /// </summary>
        [HttpGet("Test19")]
        public bool? Test19()
        {
            List<string> list = [];
            // 被全局拦截软删除
            var appTest = _appTestRepository.Select.Where(w => list.Contains(w.Id)).ToList();

            return true;
        }
    }
}
//
// public class MyDataDictionaryMappingIntercept : IDataDictionaryMappingIntercept
// {
//     private readonly AppDbContext1 _dbContext1;
//
//     public MyDataDictionaryMappingIntercept(AppDbContext1 dbContext1)
//     {
//         _dbContext1 = dbContext1;
//     }
//
//     public DictInfo HandlerData(DictInfo dictInfo, object? dbContext = null)
//     {
//         var tableName = dictInfo.DictAttribute.TableName;
//         var codeName = dictInfo.DictAttribute.CodeName;
//         var textName = dictInfo.DictAttribute.TextName;
//         var valueList = dictInfo.Data.Keys.ToList();
//
//         var codeInStr = new List<string>();
//         var par = new List<MySqlParameter>();
//         for (var i = 0; i < valueList.Count; i++)
//         {
//             var item = valueList[i];
//             var key = "?" + codeName + i;
//             codeInStr.Add(key);
//             par.Add(new MySqlParameter(key, item));
//         }
//
//         var sql = $" SELECT {codeName},{textName} FROM {tableName} WHERE {codeName} IN ({string.Join(',', codeInStr)})";
//
//         var list = _dbContext1.UnitOfWork.QueryDicBySql(sql, par.ToArray());
//
//         if (list is null)
//         {
//             return dictInfo;
//         }
//
//         foreach (var item in list)
//         {
//             var codeValue = item[codeName];
//             if (codeValue is null)
//             {
//                 continue;
//             }
//
//             dictInfo.Data[codeValue] = item[textName];
//         }
//
//         return dictInfo;
//     }
// }